﻿// JScript 文件

function MM_preloadImages() { //缓存图片 把此程序（MM_preloadImages('/images/WebResource1.gif')）加到 body 的 onLoad 事件里 
    var d = document;
    if (d.images) {
        if (!d.MM_p)(d.MM_p = new Array());

        var i, j = d.MM_p.length,
            a = MM_preloadImages.arguments;

        for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) {
                d.MM_p[j] = new Image;
                d.MM_p[j++].src = a[i];
            }
    }
}

function request(name) //读取地址栏参数
{
    var source = location.href;
    var reg = new RegExp("(^|\\?|&)" + name + "=([^&]*)(\\s|&|$)", "i");
    if (reg.test(source)) return RegExp.$2;
    return "";
}

//下拉二级栏目控制开始

var interval = null;
window.onclick = function() { closeTwoNg(); }

function showTwoNgChange(obj) {

    var obja = obj; //当前导航项;
    var objul = null; //当前下拉对象

    try {

        objul = obj.nextSibling; //设置当前下拉菜单对像
        //兼容处理
        while (objul.className != "DropdownTwoNgUl") {
            objul = objul.nextSibling;
        }

        if (objul.style.display == 'block') {
            return;
        }

    } catch (e) {

    }



    closeTwoNg(); //关闭所有下拉菜单

    if (objul.className == "DropdownTwoNgUl") {

        //obja.className = "aa oneNgC";
        //数据初始化

        $(objul).slideDown(); //显示下拉菜单

        //设置下拉菜单的位置
        var awidth = obj.offsetWidth;
        var ulwidth = objul.offsetWidth;

        if (ulwidth < awidth) {
            objul.style.width = awidth + "px";
        }

        var divwidth = objul.offsetWidth;
        var a_point = obj.getBoundingClientRect().left;

        var div_point = a_point + (awidth - divwidth) / 2;

        objul.style.left = (div_point) + "px";


        //设置下拉菜单关闭延时
        interval = setInterval("closeTwoNg()", 3000);
        objul.onmouseover = function() { clearInterval(interval); }
        objul.onmouseout = function() { interval = setInterval("closeTwoNg()", 1000); }
    }
}

//关闭下拉菜单
function closeTwoNg() {
    clearInterval(interval);
    for (var i = 0; i < $(".DropdownTwoNgUl").length; i++) {
        $(".DropdownTwoNgUl").eq(i).hide();
        //$(".DropdownTwoNgUl").eq(i).fadeOut();
    }
}

//下拉二级栏目控制结束


//iframe 高度自动适应
// 在 iframe 标识中添加：  onload="iframeAutoFitA(this)"
function iframeAutoFitA(ifm) {

    var subWeb = document.frames ? document.frames[ifm.id].document : ifm.contentDocument;

    if (ifm != null && subWeb != null) {

        ifm.height = subWeb.body.scrollHeight;

    }
}

function iframeAutoFit(ifFrameID) //让浮动框架适合网页高度
{
    var work = parent.document.getElementById(ifFrameID);
    work.style.height = document.body.scrollHeight + "px";;
}

function addLeaveword() //留言发布
{
    var nameText = document.getElementById("nameText");
    var sex = document.getElementById("sex");
    var phone = document.getElementById("phone");
    var website = document.getElementById("website");
    var oicq = document.getElementById("oicq");
    var emailtext = document.getElementById("emailtext");
    var title = document.getElementById("title");
    var contentText = document.getElementById("content");

    var errinfo = "";
    if (nameText.value == "") {
        errinfo += "·姓名不能为空！\n";
    }
    if (!(phone.value != "" || oicq.value != "" || emailtext.value != "")) {
        errinfo += "·联系电话、OICQ、Email必须输入其中一项！\n";
    }
    if (title.value == "") {
        errinfo += "·主题不能为空！\n";
    }
    if (contentText.value == "") {
        errinfo += "·内容不能为空！";
    }
    if (errinfo != "") {
        alert(errinfo);
        return false;;
    } else {
        return true;
    }
}

function callBack1(ve) {
    document.getElementById("clewText").innerText = "";

    if (ve.value) {
        alert("提交失败！");
    } else {
        var nameText = document.getElementById("nameText");
        var sex = document.getElementById("sex");
        var phone = document.getElementById("phone");
        var website = document.getElementById("website");
        var oicq = document.getElementById("oicq");
        var emailtext = document.getElementById("emailtext");
        var title = document.getElementById("title");
        var contentText = document.getElementById("contentText");

        alert("问题提交成功，我们会尽快给您回复，感谢您的支持！");
        nameText.value = "";
        phone.value = "";
        website.value = "";
        oicq.value = "";
        emailtext.value = "";
        title.value = "";
        contentText.value = "";
    }
}


function getweb(st) {
    if (st.value != "0") {
        window.open(st.value)
    }
    st.selectedIndex = 0;
}

function checkLogin(lform) {
    if (lform.username.value == "" || lform.username.value == lform.username.defaultValue) {
        alert("请输入用户名！");
        return false;
    }

    if (lform.userpassword.value == "") {
        alert("请输入密码！");
        return false;
    }

    if (lform.imgcodeTxt.value == "") {
        alert("请输入验证码！");
        return false;
    }

    return true;
}


function checkSearch(sform) {
    if (sform.sw.value == "" || sform.sw.value == sform.sw.defaultValue) {
        alert("请输入键关键字！");
        return false;
    } else {
        return true;
    }
}

function shipmentsQuery(sform) {
    if (sform.sw.value == "" || sform.sw.value == sform.sw.defaultValue) {
        alert("请输入单位名称！");
        return false;
    } else {
        openWindow(sform.action + "?sw=" + encodeURIComponent(sform.sw.value), "700", "500");
        return false;
    }
}



function opentoptouch(obj) {
    obj.parentElement.style.backgroundColor = "#1d1d1d";
    var listobj = document.getElementById("toptouch2");

    listobj.style.left = obj.parentElement.getBoundingClientRect().left;
    listobj.style.display = "block";
}

function closetoptouch(obj) {
    obj.parentElement.style.backgroundColor = "";
    var listobj = document.getElementById("toptouch2");

    listobj.style.display = "none";
}


function readCookie(name) {
    var cookieValue = "";
    var search = name + "=";
    if (document.cookie.length > 0) {
        offset = document.cookie.indexOf(search);
        if (offset != -1) {
            offset += search.length;
            end = document.cookie.indexOf(";", offset);
            if (end == -1) end = document.cookie.length;
            cookieValue = unescape(document.cookie.substring(offset, end))
        }
    }
    return cookieValue;
}

function checkLogin(lform) {
    if (lform.username.value == "" || lform.username.value == '用户名') {
        alert("请输入用户名！");
        return false;
    }

    if (lform.userpassword.value == "") {
        alert("请输入密码！");
        return false;
    }

    return true;
}

//两边固定图层
function brandload() {
    var BasisPoints = document.getElementById("bv").offsetLeft;

    if (BasisPoints > 100) {
        document.getElementById("leftFloat").style.left = (BasisPoints - 100) + "px";
        document.getElementById("rightFloat").style.left = (BasisPoints + 1110) + "px";

        document.getElementById("rightFloat").style.display = "block";
        document.getElementById("rightFloat").style.display = "block";
    } else {
        document.getElementById("leftFloat").style.display = "none";
        document.getElementById("rightFloat").style.display = "none";
    }
    setTimeout("brandload();", 20);
}


//在线客服控制
function serviceClick(obj) {
    obj.parentElement.style.display = "none";
}


//iframe 高度自动适应
// 在 iframe 标识中添加：  onload="iFrameHeight(this)"
function iFrameHeight(ifm) {

    var subWeb = document.frames ? document.frames[ifm.id].document : ifm.contentDocument;

    if (ifm != null && subWeb != null) {

        ifm.height = subWeb.body.scrollHeight;

    }
    //alert(subWeb.body.scrollHeight);

}

function brandload() {

    var leftFloat2 = document.getElementById("leftFloat2");
    var rightFloat2 = document.getElementById("rightFloat2");

    var BasisPoints = document.getElementById("bv").offsetLeft;


    if (BasisPoints > 100) {
        leftFloat2.style.left = (BasisPoints - 10 - leftFloat2.offsetWidth) + "px";
        rightFloat2.style.left = (BasisPoints + 1000 + 10) + "px";

        leftFloat2.style.display = "block";
        rightFloat2.style.display = "block";
    } else {
        leftFloat2.style.display = "none";
        rightFloat2.style.display = "none";
    }
    setTimeout("brandload();", 20);
}


function contentChange(obj, j) {
    var p_obj = obj.parentElement;
    for (var i = 0; i < p_obj.children.length; i++) {
        if (i == j) {
            p_obj.children[i].className = "on";
        } else {
            p_obj.children[i].className = "";
        }
    }

    var pp_obj = obj.parentElement.parentElement;

    for (var i = 1; i < pp_obj.children.length; i++) {
        if (i == (j + 1)) {
            //pp_obj.children[i].style.display = "block";
            $(pp_obj.children[i]).fadeIn();
        } else {
            //pp_obj.children[i].style.display = "none";
            $(pp_obj.children[i]).hide();
        }
    }
}


function subonhover(obj) {
    var dl = obj.parentElement;
    for (var i = 1; i < dl.children.length; i++) {
        dl.children[i].className = "d1";
    }
    obj.className = "d2";
}


//添加收藏夹
function addFavorite2(url, title) {
    var ua = navigator.userAgent.toLowerCase();
    if (ua.indexOf("360se") > -1) {
        alert("由于360浏览器功能限制，请按 Ctrl+D 手动收藏！");
    } else if (ua.indexOf("msie 8") > -1) {
        window.external.AddToFavoritesBar(url, title); //IE8
    } else if (document.all) {
        try {
            window.external.addFavorite(url, title);
        } catch (e) {
            alert('您的浏览器不支持,请按 Ctrl+D 手动收藏!');
        }
    } else if (window.sidebar) {
        window.sidebar.addPanel(title, url, "");
    } else {
        alert('您的浏览器不支持,请按 Ctrl+D 手动收藏!');
    }
}

//手机版块页面切换
function MobileChange(murl) {
    //平台、设备和操作系统
    var system = { win: false, mac: false, xll: false };
    //检测平台
    var p = navigator.platform;
    system.win = p.indexOf("Win") == 0;
    system.mac = p.indexOf("Mac") == 0;
    system.x11 = (p == "X11") || (p.indexOf("Linux") == 0);
    //跳转语句，如果是手机访问就自动跳转到wap.baidu.com页面
    if (system.win || system.mac || system.xll) {} else { window.location.href = murl; }
}



//内容切换
function ChangeA(obj, j) {
    var pdl = obj.parentElement;
    for (var i = 0; i < pdl.children.length; i++) {
        if (i == j) {
            pdl.children[i].className = "a1";
        } else {
            pdl.children[i].className = "a2";
        }
    }

    var pdl2 = obj.parentElement.parentElement;
    for (var i = 2; i < pdl2.children.length; i++) {
        if (i == j + 2) {
            pdl2.children[i].style.display = "block";
        } else {
            pdl2.children[i].style.display = "none";
        }
    }


}
//内容切换
function ChangeB(obj, j, cid) {
    var pdl = obj.parentElement;
    for (var i = 0; i < pdl.children.length; i++) {
        if (i == j) {
            pdl.children[i].className = "a1";
        } else {
            pdl.children[i].className = "a2";
        }
    }

    var idd = obj.parentElement.parentElement.children[3];

    var urlText = "/aspx/getmessageinfo.ashx?cid=" + cid;
    var htmlobj = $.ajax({ url: urlText, async: false });
    idd.innerHTML = htmlobj.responseText;
    document.getElementById("sw").value = "";
}

//读取字符长度
function getByteLen(val) {
    var len = 0;
    for (var i = 0; i < val.length; i++) {
        var a = val.charAt(i);
        if (a.match(/[^\x00-\xff]/ig) != null) {
            len += 2;
        } else {
            len += 1;
        }
    }
    return len;
}

//留言搜索（关键字）
function messageSearch(obj) {

    var sw = document.getElementById("sw").value;
    if (getByteLen(sw) < 4 && getByteLen(sw) > 0) {
        return;
    }
    var pdl = obj.parentElement.parentElement;
    var pdl_dt = pdl.children[1];

    for (var i = 0; i < pdl_dt.children.length; i++) {
        pdl_dt.children[i].className = "a2";
    }



    var idd = pdl.children[3];

    // var urlText = "/aspx/getmessageinfo.ashx?sw=" + sw;
    // var htmlobj = $.ajax({ url: urlText, async: false });
    // if (htmlobj.responseText == "") {
    //     idd.innerHTML = "<span style='color:red'>无搜索结果！</span>";
    // } else {
    //     idd.innerHTML = htmlobj.responseText;
    // }
    idd.innerHTML = "<span style='color:red'>无搜索结果！</span>";
}
//留言搜索（分类)
function GetMessageList(cid) {
    // var urlText = "/aspx/getmessageinfo.ashx?cid=" + cid;
    // var htmlobj = $.ajax({ url: urlText, async: false });
    // document.write(htmlobj.responseText);
}


$(document).ready(function() {

    var dialog = request("dialog");
    if (!dialog) {
        var topMain = 159; //是头部的高度加头部与nav导航之间的距离。
        var oneNgDiv = $("#bv");

        $(window).scroll(function() {

            if ($(window).scrollTop() > topMain) { //如果滚动条顶部的距离大于topMain则就nav导航就添加类.nav_scroll，否则就移除。
                oneNgDiv.addClass("NgDiv_scroll");

                $("body").css('padding-top', topMain + 80);
                $(".LogoDiv").hide();
            } else {
                oneNgDiv.removeClass("NgDiv_scroll");

                $("body").css('padding-top', topMain);
                $(".LogoDiv").show();
            }

        });
    }

})